<template>
  <dev class="image-panel" ref="coverRef"  @click="Getimg"  :style="{
    'border-radius':borderRadius,
    width:width?width+'px':'100%',
    height:height?height*scale+'px':'100%'
  }">
    <div v-if="item==1" :class="[loading?'bottom-loading':'']">
      <img  v-if="loading" class="img" src="@/assets/images/playing.gif">
      <img v-else :src="source" style="
        width: 100%;
        height: 100%;
        border-radius: 5px;
      ">
    </div>
    <div v-else class="no-image" >
      <img :src="source||imgsrc" style="">
    </div>
  </dev>
</template>
<script setup>
import {computed, getCurrentInstance, onMounted, onUnmounted, ref} from "vue";
import Utils from "@/utils/Utils.js";
import {Api} from "@/api/index.js";
const {proxy} = getCurrentInstance();
const props = defineProps({
  source:{
    type:String
  },
  width:{
    type:Number
  },
  height:{
    type:Number
  },
  lazy:{
    type:Boolean,
    default:true
  },
  fit:{
    type:String,
    default:'scale-down'
  },
  preview:{
    type:Boolean,
    default:false
  },
  img404:{
    type:String,
    default:'@/assets/images/404_cover.png'
  },
  borderRadius:{
    type:String,
    default:'5px'
  },
  defaultImage:{
    type:String,
  },
  scale:{
    type:Number,
    default:0.6
  },
  fileImages:{
    type:String
  },
  item:{
    type:Number,
    default:0
  },
  loading:{
    type:Boolean
  }
})
onMounted(()=>{
  if(props.fileImages){
    imageList.value = props.fileImages.split(',')
    for (let i = 0; i < imageList.value.length; i++) {
      Api.getFileImage(imageList.value[i]).then((res) => {
        SimgList.value.push(res.data);
      });
    }
  }
})
const showViewer = ref(false)
const coverRef = ref()
const fileImages = ref()
const fileSource = ref()
const imageList = ref()
const loadingHeight = ref()
const imgsrc = props.source;
loadingHeight.value = props.source;
if(props.fileImages){
  props.source = props.fileImages.split(',')
}
</script>

<style scoped>
.image-panel{
  position: relative;
  overflow: hidden;
  cursor: pointer;
  background: #f8f8f8;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  :deep(.el-image){
    width: 100%;
    height: 100%;
  }
  :deep(.is-loading){
    display: none;
  }
  :deep(.el-image__wrapper){
    position: relative;
    vertical-align: top;
    width: 100%;
    height: 100%;
    display: flex;
  }
 .icon-image-error{
   margin: 0 auto;
   font-size: 20px;
   color: #838383;
 }
  .loading{
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .no-image{
    width: 32px;
    height: 32px;
    text-align: center;
    color: #9f9f9f;
    img{
      width: 100%;
      height: 100%;
    }
  }
}
.bottom-loading{
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #61666d;
  img{
    width: 20px;
  }
}
</style>